/***********************************************************************
 * Module:  AnswerItem.java
 * Author:  DAC
 * Purpose: Defines the Class AnswerItem
 ***********************************************************************/
package com.group1.model;
import java.util.*;

import org.hibernate.Query;
import org.hibernate.Session;

/** @pdOid 99a5429b-6d33-4bdb-8dbf-7561a319078b */
public class AnswerItem {
   /** @pdOid 164df7ff-3523-4a37-a4fc-49161f5b2c09 */
   protected void finalize() {
      // TODO: implement
   }
   
   /** @pdOid f800645f-bc50-4588-bf1d-9679639f697c */
   public Integer ansiId;
   /** @pdOid 219e3b6e-3599-4c52-ab85-9a4a15147611 */
   public java.lang.String ansiDesc;
   /** For Fill-in-blank question
    * 
    * @pdOid cd20e64a-34a7-492e-b711-a80b5287b95e */
   public java.lang.String ansiValue;
   /** @pdOid ee40b920-36bf-4028-b2b6-a50495c78bce */
   public boolean ansiIsSolution;
   
   /** @pdRoleInfo migr=no name=QuestionImage assc=picturesForAnswerItems coll=java.util.Collection impl=java.util.HashSet mult=0..* */
   private Set questionImage = new HashSet(0);
   /** @pdRoleInfo migr=no name=Question assc=answerItemsOfQuestions mult=0..1 side=A */
   public Question question;
   
   public static List<AnswerItem> getAllAnswer(Session session)
   {
	   Query query = session.createQuery("from AnswerItem");                
	   List <AnswerItem> list = query.list();
	   return list;
   }
   
   public static AnswerItem getAnwserByID(Integer answerID, Session session)
   {
	   return (AnswerItem) session.load(AnswerItem.class, answerID);
   }
   
   public static List<AnswerItem> getAnswerByQuestion(Integer questionID,Session session)
   {
	   Query query = session.createQuery("from AnswerItem where QUESTION_ID = '" + questionID +"'");                
	   List <AnswerItem> list = query.list();
	   return list;
   }
   
   /** @pdOid c42461ea-264b-465b-9c25-aaf6f0590913 */
   public Integer getAnsiId() {
      return ansiId;
   }
   
   /** @param newAnsiId
    * @pdOid dba314dc-462c-44a0-a9c2-54cc225f269e */
   public void setAnsiId(Integer newAnsiId) {
      ansiId = newAnsiId;
   }
   
   /** @pdOid c3e77846-431e-4729-b1b8-3a7ea41e026e */
   public java.lang.String getAnsiDesc() {
      return ansiDesc;
   }
   
   /** @param newAnsiDesc
    * @pdOid 60b7096f-c57b-4d3c-ac43-800bf2863c37 */
   public void setAnsiDesc(java.lang.String newAnsiDesc) {
      ansiDesc = newAnsiDesc;
   }
   
   /** @pdOid 4bcacc86-2f12-4234-b6a7-3f490f2f76bf */
   public java.lang.String getAnsiValue() {
      return ansiValue;
   }
   
   /** @param newAnsiValue
    * @pdOid 733c621a-f4f1-48cc-ae60-130c016c83fe */
   public void setAnsiValue(java.lang.String newAnsiValue) {
      ansiValue = newAnsiValue;
   }
   
   /** @pdOid bc2ccd66-4c47-4668-8886-9caa9f9e1a53 */
   public boolean getAnsiIsSolution() {
      return ansiIsSolution;
   }
   
   /** @param newAnsiIsSolution
    * @pdOid 66933e2b-aabe-47d9-b870-13ba5d51db9e */
   public void setAnsiIsSolution(boolean newAnsiIsSolution) {
      ansiIsSolution = newAnsiIsSolution;
   }
   
   /** @pdOid 2384d1b4-9017-4e9c-9719-461eb2d7772d */
   public AnswerItem() {
      // TODO: implement
   }
   
   public Set getQuestionImage() {
		return this.questionImage;
	}

	public void setQuestionImage(Set questionImage) {
		this.questionImage = questionImage;
	}
	
//   /** @pdGenerated default getter */
//   public java.util.Collection<QuestionImage> getQuestionImage() {
//      if (questionImage == null)
//         questionImage = new java.util.HashSet<QuestionImage>();
//      return questionImage;
//   }
   
   /** @pdGenerated default iterator getter */
   public java.util.Iterator getIteratorQuestionImage() {
      if (questionImage == null)
         questionImage = new java.util.HashSet<QuestionImage>();
      return questionImage.iterator();
   }
   
//   /** @pdGenerated default setter
//     * @param newQuestionImage */
//   public void setQuestionImage(java.util.Collection<QuestionImage> newQuestionImage) {
//      removeAllQuestionImage();
//      for (java.util.Iterator iter = newQuestionImage.iterator(); iter.hasNext();)
//         addQuestionImage((QuestionImage)iter.next());
//   }
   
   /** @pdGenerated default add
     * @param newQuestionImage */
   public void addQuestionImage(QuestionImage newQuestionImage) {
      if (newQuestionImage == null)
         return;
      if (this.questionImage == null)
         this.questionImage = new java.util.HashSet<QuestionImage>();
      if (!this.questionImage.contains(newQuestionImage))
      {
         this.questionImage.add(newQuestionImage);
         newQuestionImage.setAnswerItem(this);      
      }
   }
   
   /** @pdGenerated default remove
     * @param oldQuestionImage */
   public void removeQuestionImage(QuestionImage oldQuestionImage) {
      if (oldQuestionImage == null)
         return;
      if (this.questionImage != null)
         if (this.questionImage.contains(oldQuestionImage))
         {
            this.questionImage.remove(oldQuestionImage);
            oldQuestionImage.setAnswerItem((AnswerItem)null);
         }
   }
   
   /** @pdGenerated default removeAll */
   public void removeAllQuestionImage() {
      if (questionImage != null)
      {
         QuestionImage oldQuestionImage;
         for (java.util.Iterator iter = getIteratorQuestionImage(); iter.hasNext();)
         {
            oldQuestionImage = (QuestionImage)iter.next();
            iter.remove();
            oldQuestionImage.setAnswerItem((AnswerItem)null);
         }
      }
   }
   /** @pdGenerated default parent getter */
   public Question getQuestion() {
      return question;
   }
   
   /** @pdGenerated default parent setter
     * @param newQuestion */
   public void setQuestion(Question newQuestion) {
       this.question = newQuestion;
   }

}